<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
    <!-- Bootstrap time Picker -->
    <link rel="stylesheet" href="./plugins/timepicker/bootstrap-timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="./plugins/select2/select2.min.css">
</head>
<body>
<div class="card-header">
    <button id="add" class="btn btn-primary btn-sm float-left" style="margin-right: 10px">添加员工</button>
</div>
<table id="example2" class="table table-bordered table-hover">
</table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 1000px;height: 500px">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel">系统功能信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <!-- form start -->
                <form role="form" action="" id="form1">
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单编号
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="code" type="text" class="form-control" id="c_id" placeholder=""
                                       disabled>
                                <input name="menuId" type="text" class="form-control" id="c_fid" placeholder=""
                                       style="display: none">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单名称
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="name" type="text" class="form-control" id="name" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单图标
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="icon" type="text" class="form-control" id="icon" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;跳转链接
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9">
                            <div class="form-group">
                                <input name="href" type="text" class="form-control" id="href" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单类型
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <select id="type" name="type" class="form-control select2" style="width: 100%;">
                                    <option value="1">不包含二级菜单</option>
                                    <option value="2">包含二级菜单</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;默认状态
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <select id="isSelected" name="isSelected" class="form-control select2"
                                        style="width: 100%;">
                                    <option value="1">选中</option>
                                    <option value="0">不选中</option>
                                </select>
                            </div>
                        </div>
                    </div>


                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="save1" type="button" class="btn btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 1000px;height:350px">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel">子公司信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <!-- form start -->
                <form role="form" action="" id="form2">
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;公司编号
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="code" type="text" class="form-control" id="s_id" placeholder=""
                                       disabled>
                                <input name="subMenuId" type="text" class="form-control" id="s_fid" placeholder=""
                                       style="display: none">
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单名称
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="name" type="text" class="form-control" id="s_name" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;菜单链接
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9">
                            <div class="form-group">
                                <input name="action" type="text" class="form-control" id="s_desc" value="">
                            </div>
                        </div>
                    </div>


                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="save2" type="button" class="btn btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 1000px;height:350px">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel">部门信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <!-- form start -->
                <form role="form" action="" id="form3">
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;部门编号
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="code" type="text" class="form-control" id="d_id" placeholder=""
                                       disabled>
                                <input name="did" type="text" class="form-control" id="d_fid" placeholder=""
                                       style="display: none">
                            </div>
                        </div>
                    </div>
                    <!--                    <div class="row">
                                            <div class="col-lg-2">
                                                <div class="">
                                                    <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;上级公司
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-lg-9">
                                                <div class="form-group">
                                                    <input name="sname" type="text" class="form-control" id="sname" value="">
                                                </div>
                                            </div>
                                        </div>-->
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;部门名称
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="dname" type="text" class="form-control" id="d_name" value="">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;部门介绍
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9">
                            <div class="form-group">
                                <input name="ddesc" type="text" class="form-control" id="d_desc" value="">
                            </div>
                        </div>
                    </div>


                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="save3" type="button" class="btn btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal4" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 1000px;height: 300px">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel">职位信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <!-- form start -->
                <form role="form" action="" id="form4">
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;职位编号
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="code" type="text" class="form-control" id="p_id" placeholder=""
                                       disabled>
                                <input name="pid" type="text" class="form-control" id="p_fid" placeholder=""
                                       style="display: none">
                            </div>
                        </div>
                    </div>
                    <!--                    <div class="row">
                                            <div class="col-lg-2">
                                                <div class="">
                                                    <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;职位
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-lg-9">
                                                <div class="form-group">
                                                    <input name="position" type="text" class="form-control" id="position" value="">
                                                    <input name="pid" type="text" class="form-control" id="pid" value="" style="display: none">
                                                </div>
                                            </div>
                                        </div>-->
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;职位名称
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <!-- /.form-group -->
                                <div class="form-group">
                                    <input name="pname" type="text" class="form-control" id="p_name" value="">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;职位描述
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <!-- /.form-group -->
                                <div class="form-group">
                                    <input name="pdesc" type="text" class="form-control" id="p_desc" value="">
                                </div>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="save4" type="button" class="btn btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal5" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="max-width: 1000px;height: 300px">
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title" id="myModalLabel">角色信息</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="modal-body">
                <!-- form start -->
                <form role="form" action="" id="form5">
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;角色编号
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <input name="code" type="text" class="form-control" id="u_id" placeholder=""
                                       disabled>
                                <input name="roleId" type="text" class="form-control" id="u_fid" placeholder=""
                                       style="display: none">
                            </div>
                        </div>
                    </div>
                    <!--                    <div class="row">
                                            <div class="col-lg-2">
                                                <div class="">
                                                    <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;职位
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-lg-9">
                                                <div class="form-group">
                                                    <input name="position" type="text" class="form-control" id="position" value="">
                                                    <input name="pid" type="text" class="form-control" id="pid" value="" style="display: none">
                                                </div>
                                            </div>
                                        </div>-->
                    <div class="row">
                        <div class="col-lg-2 mt-2">
                            <div class="">
                                <div style=" line-height: 1.5em;margin-top: 6px;" class="text-center"><code>*</code>&nbsp;&nbsp;角色名称
                                </div>
                            </div>
                        </div>
                        <div class="col-lg-9 mt-2">
                            <div class="form-group">
                                <!-- /.form-group -->
                                <div class="form-group">
                                    <select id="typeId" name="typeId" class="form-control select2" style="width: 100%;">
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button id="save5" type="button" class="btn btn-primary">保存</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!--点击删除按钮后弹出的页面-->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height: 200px">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">
                    提示
                </h4>
                <!--<button type="button" class="close" data-dismiss="modal" aria-hidden="true">-->
                <!--&times;-->
                <!--</button> -->
            </div>
            <div class="modal-body">
                你确定要删除该条信息吗？
                <input id="del_id" style="display: none"/>
            </div>
            <div class="modal-footer">
                <button id="delBtn" type="submit" class="btn btn-primary" value="submit">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- Select2 -->
<script src="./plugins/select2/select2.full.min.js"></script>
<script src="./plugins/select2/i18n/zh-CN.js"></script>
<!-- date-range-picker -->
<script src="./plugins/daterangepicker/daterangepicker.js"></script>
<script type="text/javascript">
    $(function () {
//        actionTo();
//        $(".select2").select2();
        //Date range picker
        //定义locale汉化插件
        var locale = {
            "format": 'YYYY-MM-DD',
            "separator": " -222 ",
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "起始时间",
            "toLabel": "结束时间'",
            "customRangeLabel": "自定义",
            "weekLabel": "W",
            "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
            "monthNames": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            "firstDay": 1
        };
        $('#u_birth').daterangepicker({
            'locale': locale,
            startDate: moment().subtract(0, 'days'),
            singleDatePicker: true,
            format: 'YYYY-MM-DD'
        });
        $('#u_birth').val(moment().subtract('0', 'days').format('YYYY-MM-DD'));

        $('#form1').bootstrapValidator({

            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },

            fields: {
                name: {
                    message: '名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                },
                href: {
                    validators: {
                        notEmpty: {
                            message: '描述不能为空'
                        }
                    }
                }
            }

        });

        $('#form2').bootstrapValidator({

            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },

            fields: {
                sname: {
                    message: '名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                },
                sdesc: {
                    validators: {
                        notEmpty: {
                            message: '描述不能为空'
                        }
                    }
                }
            }

        });


        $('#form3').bootstrapValidator({

            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },

            fields: {
                dname: {
                    message: '名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                },
                ddesc: {
                    validators: {
                        notEmpty: {
                            message: '描述不能为空'
                        }
                    }
                }
            }

        });


        $('#form4').bootstrapValidator({

            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },

            fields: {
                aid: {
                    message: '名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '名称不能为空'
                        }
                    }
                }
            }

        });


    });

    function loadData(id, type) {
        if (type == 1) {
            $(".select2").select2();
            $("#comId").val(id);
            $("#add").text("添加一级菜单");
            var user_table = $('#example2').DataTable({
                "language": {
                    "url": "./plugins/datatables/chinese.txt"
                },
                "serverSide": true,
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                destroy: true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
                "autoWidth": false,
                "ajax": {
                    "url": './menuItemList.action?contentId=' + id + '&type=' + type,
                    "type": 'POST'
                },
                columns: [
                    {
                        "data": null,
                        "title": "序号",
                        width: 80,
                        "sClass": "text-tables-center text-center",
                        "createdCell": function (nTd, sData, oData, iRow, iCol) {
                            var startnum = this.api().page() * (this.api().page.info().length);
                            $(nTd).html(iRow + 1 + startnum); //分页行号累加：$(nTd).html(iRow+1);
                        }
                    },
                    {data: 'name', 'title': '名称', 'sClass': "text-center"},
                    {
                        data: 'type', 'title': '类型', 'sClass': "text-center",
                        render: function (data, type, row) {
                            if (row.type == 1) {
                                return "不包含二级菜单";

                            } else {
                                return "包含二级菜单";
                            }

                        }
                    },
                    {data: 'href', 'title': '链接', 'sClass': "text-center"},
                    {data: 'icon', 'title': '图标', 'sClass': "text-center"},
                    {
                        data: 'isSelected', 'title': '是否选中', 'sClass': "text-center",
                        render: function (data, type, row) {
                            if (row.isSelected) {
                                return "选中状态";
                            } else {
                                return "";
                            }
                        }
                    },
                    {
                        data: 'isjob', 'title': '操作', 'sClass': "text-center", width: 100,
                        render: function (data, type, row) {
                            var id = row.menuId == undefined ? -1 : row.menuId;//-1说明是新增，其余表示为编辑
                            return "<i class='fa fa-pencil l-fa edit-btn' style='cursor: pointer' id=\'" + id + "\'></i>&nbsp;&nbsp;<i class='fa fa-trash-o m-fa del-btn' style='cursor: pointer' id=\'" + id + "\'></i>";
                        }
                    }
                ]
            });


            //点击编辑图标出现编辑框
            $("#example2 tbody").unbind('click').on("click", ".edit-btn", function () {
                var id = $(this).attr("id");
                if (id != -1) {
                    var url = encodeURI("./menuDetail.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {
                            "contentId": id
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                //刷新表格
                                var data = result.data;
                                $("#c_id").val("FU00" + data.menuId);
                                $("#c_fid").val(data.menuId);
                                $("#name").val(data.name);
                                $("#href").val(data.href);
                                $("#icon").val(data.icon);

                                $("#type").val(data.type).select2();
                                $("#isSelected").val(data.isSelected).select2();

                                $('#myModal1').modal('show');
                            } else {

                            }
                        },
                        dataType: "json"
                    });
                } else {
                    $('#myModal1').modal('show');
                }

            });

            //删除
            $("#example2 tbody").on("click", ".del-btn", function () {
                var id = $(this).attr("id");
                $("#del_id").val(id);

                $('#deleteModal').modal('show');
                $("#deleteModal").bind('hide.bs.modal', function () {
                    $(".modal-backdrop").remove();
                });

                $("#deleteModal").on('hidden.bs.modal', '.modal', function () {
                    $(this).removeData('bs.modal');
                });


            });


            //证照属性设置保存信息
            $("#save1").on("click", function SaveData() {
                    $("#form1").bootstrapValidator('validate');//提交验证
                    if ($("#form1").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
                        var data = $('#form1').serialize();
                        //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                        var submitData = decodeURIComponent(data, true);
                        //submitData是解码后的表单数据，结果同上
                        data += "&contentId=" + $("#c_fid").val();

                        var url = encodeURI("./saveMenu.action");
                        $.ajax({
                            type: 'POST',
                            url: url,
                            data: data,
                            dataType: "json",
                            success: function (result) {
                                if (result.success) {
                                    if ($("#c_fid").val() != null && $("#c_fid").val() != "") {
                                        updateNode(result.Id, result.name, result.href);
                                    } else {
                                        addNode(result.Id, result.name, result.href);
                                    }


                                    //刷新表格
                                    $("#myModal1").modal('hide');  //手动关闭
                                    userSearchBtn();
                                } else {
                                    //刷新表格
                                    $("#myModal1").modal('hide');  //手动关闭
                                    userSearchBtn();
                                }

                                $("#myModal1").bind('hide.bs.modal', function () {
                                    $(".modal-backdrop").remove();
                                });
                            },
                            dataType: "json"
                        });

                    }

                }
            );

            //证照属性设置新添加信息
            $("#add").on("click", function SaveData() {
                $("#c_id").val("");
                $("#c_fid").val("");
                $("#c_name").val("");
                $("#c_desc").val("");
                $('#myModal1').modal('show');
            });


            //证照属性设置删除
            $("#delBtn").on("click", function () {
                var id = $("#del_id").val();
                var data = {"contentId": id};
                var url = "./deleteMenu.action";
                //执行删除
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            deleteNode($("#del_id").val());
                            userSearchBtn();
                        } else {
                            userSearchBtn();
                        }
                        $('#deleteModal').modal('hide');
                    },
                    dataType: "json"
                });

            });
            function userSearchBtn() {
                user_table.ajax.reload();   // 这边的user_table，是由初始化datatables的变量名
            }

        } else if (type == 2) {
            $("#subComId").val(id);
            $("#add").text("添加二级菜单");
            var user_table = $('#example2').DataTable({
                "language": {
                    "url": "./plugins/datatables/chinese.txt"
                },
                "serverSide": true,
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                destroy: true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
                "autoWidth": false,
                "ajax": {
                    "url": './menuItemList.action?contentId=' + id + '&type=' + type,
                    "type": 'POST'
                },
                columns: [
                    {
                        "data": null,
                        "title": "序号",
                        width: 80,
                        "sClass": "text-tables-center text-center",
                        "createdCell": function (nTd, sData, oData, iRow, iCol) {
                            var startnum = this.api().page() * (this.api().page.info().length);
                            $(nTd).html(iRow + 1 + startnum); //分页行号累加：$(nTd).html(iRow+1);
                        }
                    },
                    {data: 'menu.name', 'title': '上级', 'sClass': "text-center"},
                    {data: 'name', 'title': '名称', 'sClass': "text-center"},
                    {data: 'action', 'title': '链接', 'sClass': "text-center"},
                    {
                        data: 'isjob', 'title': '操作', 'sClass': "text-center", width: 100,
                        render: function (data, type, row) {
                            var id = row.subMenuId == undefined ? -1 : row.subMenuId;//-1说明是新增，其余表示为编辑
                            return "<i class='fa fa-pencil l-fa edit-btn' style='cursor: pointer' id=\'" + id + "\'></i>&nbsp;&nbsp;<i class='fa fa-trash-o m-fa del-btn' style='cursor: pointer' id=\'" + id + "\'></i>";
                        }
                    }
                ]
            });


            //点击编辑图标出现编辑框
            $("#example2 tbody").unbind('click').on("click", ".edit-btn", function () {
                var id = $(this).attr("id");
                if (id != -1) {
                    var url = encodeURI("./subMenuDetail.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {
                            "contentId": id
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                //刷新表格
                                var data = result.data;
                                $("#s_id").val("FU00" + data.subMenuId);
                                $("#s_fid").val(data.subMenuId);
                                $("#s_name").val(data.name);
                                $("#s_desc").val(data.action);

                                $('#myModal2').modal('show');
                            } else {

                            }
                        },
                        dataType: "json"
                    });
                } else {
                    $('#myModal2').modal('show');
                }

            });

            //删除
            $("#example2 tbody").on("click", ".del-btn", function () {
                var id = $(this).attr("id");
                $("#del_id").val(id);

                $('#deleteModal').modal('show');
                $("#deleteModal").bind('hide.bs.modal', function () {
                    $(".modal-backdrop").remove();
                });

                $("#deleteModal").on('hidden.bs.modal', '.modal', function () {
                    $(this).removeData('bs.modal');
                });


            });


            //保存按钮
            $("#example2 tbody").on("click", ".save-btn", function () {
                var id = $(this).attr("id");
                var tds = $(this).parents("tr").children();
                var sTds = tds.length;
                var lisval = [];
                for (var i = 0; i < sTds; i++) {
                    if (i < sTds - 1)
                        lisval.push(tds.eq(i).children("input").val());
                    else lisval.push(tds.eq(i).children("input").val())
                }
                if (i == sTds - 1) lisval.push();
                if (lisval[1] == "") {
                    toNotification("警告！", "证照属性设置不能为空！", "warning");
                    return false;
                } else if (lisval[1].length > 10) {
                    toNotification("警告！", "证照属性设置不能超过十个字符！", "warning");
                    return false;
                } else {
                    $.each(tds, function (i, val) {
                        var jqob = $(val);
                        //把input变为字符串
                        if (!jqob.has('i').length) {
                            var txt = jqob.children("input").val();
                            jqob.html(txt);
                        }
                    });
                    $(this).toggleClass("edit-btn fa-pencil");
                    $(this).toggleClass("save-btn fa-save");
                    //保存数据
                    SaveData(lisval, id);
                }

            });


            //证照属性设置保存信息
            $("#save2").on("click", function SaveData() {
                $("#form2").bootstrapValidator('validate');//提交验证
                if ($("#form2").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
                    var data = $('#form2').serialize();
                    //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                    var submitData = decodeURIComponent(data, true);
                    //submitData是解码后的表单数据，结果同上
                    data += "&contentId=" + id + "&type=" + type;
                    var url = encodeURI("./saveSubMenu.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: data,
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                if ($("#s_fid").val() != null && $("#s_fid").val() != "") {
                                    updateNode(result.Id, result.name, result.href);
                                } else {
                                    addNode(result.Id, result.name, result.href);
                                }
                                //刷新表格
                                $("#myModal2").modal('hide');  //手动关闭
                                userSearchBtn();
                            } else {
                                //刷新表格
                                $("#myModal2").modal('hide');  //手动关闭
                                userSearchBtn();
                            }

                            $("#myModal2").bind('hide.bs.modal', function () {
                                $(".modal-backdrop").remove();
                            });
                        },
                        dataType: "json"
                    });
                }

            });

            //证照属性设置新添加信息
            $("#add").on("click", function SaveData() {
                $("#s_id").val("");
                $("#s_fid").val("");
                $("#s_name").val("");
                $("#s_desc").val("");
                $('#myModal2').modal('show');
            });


            //证照属性设置删除
            $("#delBtn").on("click", function () {
                var id = $("#del_id").val();
                var data = {"contentId": id};
                var url = "./deleteSubMenu.action";
                //执行删除
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            deleteNode($("#del_id").val());
                            userSearchBtn();
                        } else {
                            userSearchBtn();
                        }
                        $('#deleteModal').modal('hide');
                    },
                    dataType: "json"
                });

            });
            function userSearchBtn() {
                user_table.ajax.reload();   // 这边的user_table，是由初始化datatables的变量名
            }

        } else if (type == 3) {
            $("#depId").val(id);
            $("#add").text("绑定管理员角色");
            var user_table = $('#example2').DataTable({
                "language": {
                    "url": "./plugins/datatables/chinese.txt"
                },
                "serverSide": true,
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                destroy: true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
                "autoWidth": false,
                "ajax": {
                    "url": './RoleByFuncList.action?contentId=' + id + '&type=' + type,
                    "type": 'POST'
                },
                columns: [
                    {
                        "data": null,
                        "title": "序号",
                        width: 80,
                        "sClass": "text-tables-center text-center",
                        "createdCell": function (nTd, sData, oData, iRow, iCol) {
                            var startnum = this.api().page() * (this.api().page.info().length);
                            $(nTd).html(iRow + 1 + startnum); //分页行号累加：$(nTd).html(iRow+1);
                        }
                    },
                    {data: 'name', 'title': '角色名称', 'sClass': "text-center"},
                    {
                        data: 'isjob', 'title': '操作', 'sClass': "text-center", width: 100,
                        render: function (data, type, row) {
                            var id = row.typeId == undefined ? -1 : row.typeId;//-1说明是新增，其余表示为编辑
                            return "<i class='fa fa-trash-o m-fa del-btn' style='cursor: pointer' id=\'" + id + "\'></i>";
                        }
                    }
                ]
            });

            $(".select2").select2({
                ajax: {
                    type: 'GET',
                    url: "./RoleList.action",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        return {
                            search: params.term, // search term 请求参数 ， 请求框中输入的参数
                            page: params.page,
                            length: 10,// 每页显示多少行
                            type: 3
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        var itemList = [];//当数据对象不是{id:0,text:'ANTS'}这种形式的时候，可以使用类似此方法创建新的数组对象
                        var arr = data.data;
                        for (item in arr) {
                            itemList.push({id: arr[item].typeId, text: arr[item].name})
                        }
                        return {
                            results: itemList,//itemList
                            pagination: {
                                more: (params.page * 30) < data.recordsTotal
                            }
                        };
                    },
                    cache: false
                },
                placeholder: '请选择',//默认文字提示
                language: "zh-CN",
                delay: 250,// 延迟显示
                tags: true,//允许手动添加
                allowClear: true,//允许清空
                escapeMarkup: function (markup) {
                    return markup;
                }, // 自定义格式化防止xss注入
                minimumInputLength: 1,//最少输入多少个字符后开始查询
                formatResult: function formatRepo(repo) {
                    return repo.text;
                }, // 函数用来渲染结果
                formatSelection: function formatRepoSelection(repo) {
                    return repo.text;
                } // 函数用于呈现当前的选择
            });


            //点击编辑图标出现编辑框
            $("#example2 tbody").unbind('click').on("click", ".edit-btn", function () {
                var id = $(this).attr("id");
                if (id != -1) {
                    var url = encodeURI("./departmentDetail.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {
                            "contentId": id
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                //刷新表格
                                var data = result.data;
                                $("#d_id").val("FU00" + data.did);
                                $("#d_fid").val(data.did);
                                $("#d_name").val(data.dname);
                                $("#d_desc").val(data.desc);

                                $('#myModal3').modal('show');
                            } else {

                            }
                        },
                        dataType: "json"
                    });
                } else {
                    $('#myModal3').modal('show');
                }

            });

            //删除
            $("#example2 tbody").on("click", ".del-btn", function () {
                var id = $(this).attr("id");
                $("#del_id").val(id);

                $('#deleteModal').modal('show');
                $("#deleteModal").bind('hide.bs.modal', function () {
                    $(".modal-backdrop").remove();
                });

                $("#deleteModal").on('hidden.bs.modal', '.modal', function () {
                    $(this).removeData('bs.modal');
                });


            });


            //保存按钮
            $("#example2 tbody").on("click", ".save-btn", function () {
                var id = $(this).attr("id");
                var tds = $(this).parents("tr").children();
                var sTds = tds.length;
                var lisval = [];
                for (var i = 0; i < sTds; i++) {
                    if (i < sTds - 1)
                        lisval.push(tds.eq(i).children("input").val());
                    else lisval.push(tds.eq(i).children("input").val())
                }
                if (i == sTds - 1) lisval.push();
                if (lisval[1] == "") {
                    toNotification("警告！", "证照属性设置不能为空！", "warning");
                    return false;
                } else if (lisval[1].length > 10) {
                    toNotification("警告！", "证照属性设置不能超过十个字符！", "warning");
                    return false;
                } else {
                    $.each(tds, function (i, val) {
                        var jqob = $(val);
                        //把input变为字符串
                        if (!jqob.has('i').length) {
                            var txt = jqob.children("input").val();
                            jqob.html(txt);
                        }
                    });
                    $(this).toggleClass("edit-btn fa-pencil");
                    $(this).toggleClass("save-btn fa-save");
                    //保存数据
                    SaveData(lisval, id);
                }

            });


            //证照属性设置保存信息
            $("#save5").on("click", function SaveData() {
                /* $("#form5").bootstrapValidator('validate');//提交验证
                 if ($("#form5").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码

                 }*/

                var data = $('#form5').serialize();
                //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                var submitData = decodeURIComponent(data, true);
                //submitData是解码后的表单数据，结果同上
                data += "&contentId=" + id + "&type=" + type;
                var url = encodeURI("./saveUserRole.action");
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        } else {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        }

                        $("#myModal5").bind('hide.bs.modal', function () {
                            $(".modal-backdrop").remove();
                        });
                    },
                    dataType: "json"
                });

            });

            //证照属性设置新添加信息
            $("#add").on("click", function SaveData() {
                $("#d_id").val("");
                $("#d_fid").val("");
                $("#d_name").val("");
                $("#d_desc").val("");
                $('#myModal5').modal('show');
            });


            //证照属性设置删除
            $("#delBtn").on("click", function () {
                var id = $("#del_id").val();
                var type_id = $("#depId").val();
                var data = {"contentId": type_id,"typeId":id};
                var url = "./deleteUserRole.action";
                //执行删除
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        userSearchBtn();
                        $('#deleteModal').modal('hide');
                    },
                    dataType: "json"
                });

            });
            function userSearchBtn() {
                user_table.ajax.reload();   // 这边的user_table，是由初始化datatables的变量名
            }

        } else if (type == 4) {
            $("#add").text("添加职位");

            $("#posId").val(id);
            var user_table = $('#example2').DataTable({
                "language": {
                    "url": "./plugins/datatables/chinese.txt"
                },
                "serverSide": true,
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                destroy: true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
                "autoWidth": false,
                "ajax": {
                    "url": './ComPanyList.action?contentId=' + id + '&type=' + type,
                    "type": 'POST'
                },
                columns: [
                    {
                        "data": null,
                        "title": "序号",
                        "sClass": "text-tables-center text-center",
                        "createdCell": function (nTd, sData, oData, iRow, iCol) {
                            var startnum = this.api().page() * (this.api().page.info().length);
                            $(nTd).html(iRow + 1 + startnum); //分页行号累加：$(nTd).html(iRow+1);
                        }
                    },
                    {data: 'pname', 'title': '名称', 'sClass': "text-center"},
                    {data: 'pdesc', 'title': '描述', 'sClass': "text-center"},
                    {
                        data: 'isjob', 'title': '操作', 'sClass': "text-center",
                        render: function (data, type, row) {
                            var id = row.pid == undefined ? -1 : row.pid;//-1说明是新增，其余表示为编辑
                            return "<i class='fa fa-pencil l-fa edit-btn' style='cursor: pointer' id=\'" + id + "\'></i>&nbsp;&nbsp;<i class='fa fa-trash-o m-fa del-btn' style='cursor: pointer' id=\'" + id + "\'></i>";
                        }
                    }
                ]
            });


            //点击编辑图标出现编辑框
            $("#example2 tbody").unbind('click').on("click", ".edit-btn", function () {
                var id = $(this).attr("id");
                if (id != -1) {
                    var url = encodeURI("./positionDetail.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {
                            "contentId": id
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                //刷新表格
                                var data = result.data;
                                $("#p_id").val("FU00" + data.pid);
                                $("#p_fid").val(data.pid);
                                $("#p_name").val(data.pname);
                                $("#p_desc").val(data.pdesc);

                                $('#myModal4').modal('show');
                            } else {

                            }
                        },
                        dataType: "json"
                    });
                } else {
                    $('#myModal4').modal('show');
                }

            });

            //删除
            $("#example2 tbody").on("click", ".del-btn", function () {
                var id = $(this).attr("id");
                $("#del_id").val(id);

                $('#deleteModal').modal('show');
                $("#deleteModal").bind('hide.bs.modal', function () {
                    $(".modal-backdrop").remove();
                });

                $("#deleteModal").on('hidden.bs.modal', '.modal', function () {
                    $(this).removeData('bs.modal');
                });


            });


            //保存按钮
            $("#example2 tbody").on("click", ".save-btn", function () {
                var id = $(this).attr("id");
                var tds = $(this).parents("tr").children();
                var sTds = tds.length;
                var lisval = [];
                for (var i = 0; i < sTds; i++) {
                    if (i < sTds - 1)
                        lisval.push(tds.eq(i).children("input").val());
                    else lisval.push(tds.eq(i).children("input").val())
                }
                if (i == sTds - 1) lisval.push();
                if (lisval[1] == "") {
                    toNotification("警告！", "证照属性设置不能为空！", "warning");
                    return false;
                } else if (lisval[1].length > 10) {
                    toNotification("警告！", "证照属性设置不能超过十个字符！", "warning");
                    return false;
                } else {
                    $.each(tds, function (i, val) {
                        var jqob = $(val);
                        //把input变为字符串
                        if (!jqob.has('i').length) {
                            var txt = jqob.children("input").val();
                            jqob.html(txt);
                        }
                    });
                    $(this).toggleClass("edit-btn fa-pencil");
                    $(this).toggleClass("save-btn fa-save");
                    //保存数据
                    SaveData(lisval, id);
                }

            });


            //证照属性设置保存信息
            $("#save4").on("click", function SaveData() {
                $("#form4").bootstrapValidator('validate');//提交验证
                if ($("#form4").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
                    var data = $('#form4').serialize();
                    //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                    var submitData = decodeURIComponent(data, true);
                    //submitData是解码后的表单数据，结果同上
                    data += "&contentId=" + id + "&type=" + type;
                    var url = encodeURI("./savePosition.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: data,
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                if ($("#p_fid").val() != null && $("#p_fid").val() != "") {
                                    updateNode(result.Id, result.name, result.href);
                                } else {
                                    addNode(result.Id, result.name, result.href);
                                }
                                //刷新表格
                                $("#myModal4").modal('hide');  //手动关闭
                                userSearchBtn();
                            } else {
                                //刷新表格
                                $("#myModal4").modal('hide');  //手动关闭
                                userSearchBtn();
                            }

                            $("#myModal4").bind('hide.bs.modal', function () {
                                $(".modal-backdrop").remove();
                            });
                        },
                        dataType: "json"
                    });
                }

            });

            //证照属性设置保存信息
            $("#save5").on("click", function SaveData() {
                var data = $('#form5').serialize();
                //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                var submitData = decodeURIComponent(data, true);
                //submitData是解码后的表单数据，结果同上
                data += "&contentId=" + id + "&type=" + type;
                var url = encodeURI("./savePositionUser.action");
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        } else {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        }

                        $("#myModal5").bind('hide.bs.modal', function () {
                            $(".modal-backdrop").remove();
                        });
                    },
                    dataType: "json"
                });
            });

            //证照属性设置新添加信息
            $("#add").on("click", function SaveData() {
                $("#p_id").val("");
                $("#p_fid").val("");
                $("#p_name").val("");
                $("#p_desc").val("");
                $('#myModal4').modal('show');
            });

            //证照属性设置新添加信息
            $("#addUser").on("click", function SaveData() {
                $("#u_id").val("");
                $("#u_fid").val("");
                $("#u_name").val("");
                $("#u_position").val("");
                $("#u_school").val("");
                $("#u_tel").val("");
                $("#u_email").val("");
                $("#u_birth").val("");
                $('#myModal5').modal('show');
            });


            //证照属性设置删除
            $("#delBtn").on("click", function () {
                var id = $("#del_id").val();
                var type_id=$("#depId").val();
                var data = {"contentId": id,"typeId":type_id};
                var url = "./deletePosition.action";
                //执行删除
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            deleteNode($("#del_id").val());
                            userSearchBtn();
                        } else {
                            userSearchBtn();
                        }
                        $('#deleteModal').modal('hide');
                    },
                    dataType: "json"
                });

            });

            function userSearchBtn() {
                user_table.ajax.reload();   // 这边的user_table，是由初始化datatables的变量名
            }

            $(".select2").select2({
                ajax: {
                    type: 'GET',
                    url: "./UserList.action",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        return {
                            search: params.term, // search term 请求参数 ， 请求框中输入的参数
                            page: params.page,
                            length: 10,// 每页显示多少行
                            type: 3
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        var itemList = [];//当数据对象不是{id:0,text:'ANTS'}这种形式的时候，可以使用类似此方法创建新的数组对象
                        var arr = data.data;
                        for (item in arr) {
                            itemList.push({id: arr[item].aid, text: arr[item].name})
                        }
                        return {
                            results: itemList,//itemList
                            pagination: {
                                more: (params.page * 30) < data.recordsTotal
                            }
                        };
                    },
                    cache: false
                },
                placeholder: '请选择',//默认文字提示
                language: "zh-CN",
                delay: 250,// 延迟显示
                tags: true,//允许手动添加
                allowClear: true,//允许清空
                escapeMarkup: function (markup) {
                    return markup;
                }, // 自定义格式化防止xss注入
                minimumInputLength: 1,//最少输入多少个字符后开始查询
                formatResult: function formatRepo(repo) {
                    return repo.text;
                }, // 函数用来渲染结果
                formatSelection: function formatRepoSelection(repo) {
                    return repo.text;
                } // 函数用于呈现当前的选择
            });


        } else if (type == 5) {
            $("#add").text("添加员工");

            $("#posId").val(id);
            var user_table = $('#example2').DataTable({
                "language": {
                    "url": "./plugins/datatables/chinese.txt"
                },
                "serverSide": true,
                "paging": true,
                "lengthChange": true,
                "searching": true,
                "ordering": true,
                "info": true,
                destroy: true, //Cannot reinitialise DataTable,解决重新加载表格内容问题
                "autoWidth": false,
                "ajax": {
                    "url": './ComPanyList.action?contentId=' + id + '&type=' + type,
                    "type": 'POST'
                },
                columns: [
                    {
                        "data": null,
                        "title": "序号",
                        "sClass": "text-tables-center text-center",
                        "createdCell": function (nTd, sData, oData, iRow, iCol) {
                            var startnum = this.api().page() * (this.api().page.info().length);
                            $(nTd).html(iRow + 1 + startnum); //分页行号累加：$(nTd).html(iRow+1);
                        }
                    },
                    {data: 'name', 'title': '姓名', 'sClass': "text-center"},
                    {
                        data: 'img', 'title': "头像", 'sClass': "text-center",
                        "width": 100,
                        render: function (data, type, row) {
                            var img = row.img == undefined ? "" : row.img;//-1说明是新增，其余表示为编辑
                            return "<a href=" + img + " target='_blank'><img src='" + img + "' style='max-width:100%;height: 100px'></a>";
                        }
                    },
                    {data: 'birth', 'title': '生日', 'sClass': "text-center"},
                    {
                        data: '性别', 'sClass': "text-center",
                        render: function (data, type, row) {
                            if (row.sex == 1) {
                                return "男";
                            }
                            return "女";
                        }
                    },
                    {data: 'createtime', 'title': '创建时间', 'sClass': "text-center"},
                    {data: 'lastloginTime', 'title': '最后登录时间', 'sClass': "text-center"},
                    {data: 'tel', 'title': '联系方式', 'sClass': "text-center"},
                    {
                        data: 'isjob', 'title': '操作', 'sClass': "text-center",
                        render: function (data, type, row) {
                            var id = row.aid == undefined ? -1 : row.aid;//-1说明是新增，其余表示为编辑
                            return "<i class='fa fa-trash-o m-fa del-btn' style='cursor: pointer' id=\'" + id + "\'></i>";
                        }
                    }
                ]
            });


            //点击编辑图标出现编辑框
            $("#example2 tbody").unbind('click').on("click", ".edit-btn", function () {
                var id = $(this).attr("id");
                if (id != -1) {
                    var url = encodeURI("./getUserDetail.action");
                    $.ajax({
                        type: 'POST',
                        url: url,
                        data: {
                            "contentId": id
                        },
                        dataType: "json",
                        success: function (result) {
                            if (result.success) {
                                //刷新表格
                                var data = result.data;
                                $("#u_id").val("FU00" + data.aid);
                                $("#u_fid").val(data.aid);
                                $("#u_name").val(data.name);
                                $("#u_position").val(data.position.pname);
                                $("#u_tel").val(data.tel);
                                $("#u_birth").val(data.birth);

                                var options = $("#isjob").children();
                                $.each(options, function (i, val) {
                                    var jqob = $(val);
                                    //把input变为字符串
                                    if (jqob.val() == data.isjob) {
                                        $("#isjob").val(jqob.val()).trigger("change");
                                        jqob.attr("selected", "selected");
                                    }
                                });

                                var options = $("#sex").children();
                                $.each(options, function (i, val) {
                                    var jqob = $(val);
                                    //把input变为字符串
                                    if (jqob.val() == data.sex) {
                                        $("#sex").val(jqob.val()).trigger("change");
                                        jqob.attr("selected", "selected");
                                    }
                                });

                                $('#myModal4').modal('show');
                            } else {

                            }
                        },
                        dataType: "json"
                    });
                } else {
                    $('#myModal4').modal('show');
                }

            });

            //删除
            $("#example2 tbody").on("click", ".del-btn", function () {
                var id = $(this).attr("id");
                $("#del_id").val(id);

                $('#deleteModal').modal('show');
                $("#deleteModal").bind('hide.bs.modal', function () {
                    $(".modal-backdrop").remove();
                });

                $("#deleteModal").on('hidden.bs.modal', '.modal', function () {
                    $(this).removeData('bs.modal');
                });


            });


            //保存按钮
            $("#example2 tbody").on("click", ".save-btn", function () {
                var id = $(this).attr("id");
                var tds = $(this).parents("tr").children();
                var sTds = tds.length;
                var lisval = [];
                for (var i = 0; i < sTds; i++) {
                    if (i < sTds - 1)
                        lisval.push(tds.eq(i).children("input").val());
                    else lisval.push(tds.eq(i).children("input").val())
                }
                if (i == sTds - 1) lisval.push();
                if (lisval[1] == "") {
                    toNotification("警告！", "证照属性设置不能为空！", "warning");
                    return false;
                } else if (lisval[1].length > 10) {
                    toNotification("警告！", "证照属性设置不能超过十个字符！", "warning");
                    return false;
                } else {
                    $.each(tds, function (i, val) {
                        var jqob = $(val);
                        //把input变为字符串
                        if (!jqob.has('i').length) {
                            var txt = jqob.children("input").val();
                            jqob.html(txt);
                        }
                    });
                    $(this).toggleClass("edit-btn fa-pencil");
                    $(this).toggleClass("save-btn fa-save");
                    //保存数据
                    SaveData(lisval, id);
                }

            });


            //证照属性设置保存信息
            $("#save4").on("click", function SaveData() {
                var data = $('#form4').serialize();
                //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                var submitData = decodeURIComponent(data, true);
                //submitData是解码后的表单数据，结果同上
                data += "&contentId=" + id + "&type=" + type;
                var url = encodeURI("./savePosition.action");
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            addNode(result.name, result.href);
                            //刷新表格
                            $("#myModal4").modal('hide');  //手动关闭
                            userSearchBtn();
                        } else {
                            //刷新表格
                            $("#myModal4").modal('hide');  //手动关闭
                            userSearchBtn();
                        }

                        $("#myModal4").bind('hide.bs.modal', function () {
                            $(".modal-backdrop").remove();
                        });
                    },
                    dataType: "json"
                });
            });

            //证照属性设置保存信息
            $("#save5").on("click", function SaveData() {
                var data = $('#form5').serialize();
                //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
                var submitData = decodeURIComponent(data, true);
                //submitData是解码后的表单数据，结果同上
                data += "&contentId=" + id + "&type=" + type;
                var url = encodeURI("./savePositionUser.action");
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        } else {
                            //刷新表格
                            $("#myModal5").modal('hide');  //手动关闭
                            userSearchBtn();
                        }

                        $("#myModal5").bind('hide.bs.modal', function () {
                            $(".modal-backdrop").remove();
                        });
                    },
                    dataType: "json"
                });
            });


            //证照属性设置新添加信息
            $("#add").on("click", function SaveData() {
                $("#u_id").val("");
                $("#u_fid").val("");
                $("#u_name").val("");
                $("#u_position").val("");
                $("#u_school").val("");
                $("#u_tel").val("");
                $("#u_email").val("");
                $("#u_birth").val("");
                $('#myModal5').modal('show');
            });


            //证照属性设置删除
            $("#delBtn").on("click", function () {
                var id = $("#del_id").val();
                var data = {"contentId": id};
                var url = "./deleteAccountPosition.action";
                //执行删除
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    dataType: "json",
                    success: function (result) {
                        if (result.success) {

                            userSearchBtn();
                        } else {
                            userSearchBtn();
                        }
                        $('#deleteModal').modal('hide');
                    },
                    dataType: "json"
                });

            });

            function userSearchBtn() {
                user_table.ajax.reload();   // 这边的user_table，是由初始化datatables的变量名
            }

            $(".select2").select2({
                ajax: {
                    type: 'GET',
                    url: "./UserList.action",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {
                        return {
                            search: params.term, // search term 请求参数 ， 请求框中输入的参数
                            page: params.page,
                            length: 10,// 每页显示多少行
                            type: 3
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                        var itemList = [];//当数据对象不是{id:0,text:'ANTS'}这种形式的时候，可以使用类似此方法创建新的数组对象
                        var arr = data.data;
                        for (item in arr) {
                            itemList.push({id: arr[item].aid, text: arr[item].name})
                        }
                        return {
                            results: itemList,//itemList
                            pagination: {
                                more: (params.page * 30) < data.recordsTotal
                            }
                        };
                    },
                    cache: false
                },
                placeholder: '请选择',//默认文字提示
                language: "zh-CN",
                delay: 250,// 延迟显示
                tags: true,//允许手动添加
                allowClear: true,//允许清空
                escapeMarkup: function (markup) {
                    return markup;
                }, // 自定义格式化防止xss注入
                minimumInputLength: 1,//最少输入多少个字符后开始查询
                formatResult: function formatRepo(repo) {
                    return repo.text;
                }, // 函数用来渲染结果
                formatSelection: function formatRepoSelection(repo) {
                    return repo.text;
                } // 函数用于呈现当前的选择
            });


        }


    }
</script>
</body>

</html>
